﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RacePlatformer;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Dwarfs.Manager;

namespace Dwarfs.Screens
{
    public class MenuScreen : Screen
    {
        private Color newGameColor = Color.Black,
            loadGameColor = Color.Black,
            optionColor = Color.Black,
            ExitGameColor = Color.Black;
        private enum selectedIndex
        {
            NewGame,
            LoadGame,
            Options,
            ExitGame
        };
        private selectedIndex currentSelectedIndex = 0;
        public MenuScreen(MainGame maingame)
            : base(maingame)
        {

        }
        public override void UpdateMenu()
        {
            KeyboardState currentKeyboardState = Keyboard.GetState();
            maingame.soundmanager.playBackgroundSound(this);
            if (previousKeyboardState.IsKeyDown(Keys.Enter) && currentKeyboardState.IsKeyUp(Keys.Enter))
            {
                switch (currentSelectedIndex)
                {
                    case selectedIndex.NewGame:
                        SoundManager.stopBackgroundSound();
                        maingame.inializeGame();
                        break;
                }
            }
            if (previousKeyboardState.IsKeyDown(Keys.Down) && currentKeyboardState.IsKeyUp(Keys.Down))
            {
                if (currentSelectedIndex != selectedIndex.ExitGame)
                {
                    currentSelectedIndex++;
                }
                else
                {
                    currentSelectedIndex = 0;
                }
            }

            if (previousKeyboardState.IsKeyDown(Keys.Up) && currentKeyboardState.IsKeyUp(Keys.Up))
            {
                if (currentSelectedIndex != selectedIndex.NewGame)
                {
                    currentSelectedIndex--;
                }
                else
                {
                    currentSelectedIndex = selectedIndex.ExitGame;
                }
            }
            previousKeyboardState = currentKeyboardState;
        }
        public override void DrawScreen(Microsoft.Xna.Framework.GameTime gameTime, SpriteBatch batch)
        {
            batch.Draw(screenBackground, new Rectangle(0, 0, MainGame.SCREEN_WIDTH, MainGame.SCREEN_HEIGHT), Color.White);
            switch (currentSelectedIndex)
            {
                case selectedIndex.NewGame:
                    newGameColor = Color.Red;
                    break;
                case selectedIndex.LoadGame:
                    loadGameColor = Color.Gold;
                    break;
                case selectedIndex.Options:
                    optionColor = Color.Blue;
                    break;
                case selectedIndex.ExitGame:
                    ExitGameColor = Color.Yellow;
                    break;
            }
            batch.DrawString(screenFont, "New Game", new Vector2((MainGame.SCREEN_WIDTH / 2) - selectedIndex.NewGame.ToString().Length, (MainGame.SCREEN_HEIGHT / 2) - 50), newGameColor);
            batch.DrawString(screenFont, "Load Game", new Vector2((MainGame.SCREEN_WIDTH / 2) - selectedIndex.LoadGame.ToString().Length, (MainGame.SCREEN_HEIGHT / 2)), loadGameColor);
            batch.DrawString(screenFont, "Options", new Vector2((MainGame.SCREEN_WIDTH / 2) - selectedIndex.Options.ToString().Length, (MainGame.SCREEN_HEIGHT / 2) + 50), optionColor);
            batch.DrawString(screenFont, "Exit Game", new Vector2((MainGame.SCREEN_WIDTH / 2) - selectedIndex.ExitGame.ToString().Length, (MainGame.SCREEN_HEIGHT / 2) + 100), ExitGameColor);
            resetColors();
        }
        public void resetColors()
        {
            newGameColor = Color.Black;
            loadGameColor = Color.Black;
            optionColor = Color.Black;
            ExitGameColor = Color.Black;
        }
        public override void LoadContent()
        {
            screenBackground = maingame.Content.Load<Texture2D>("screens/menuScreen");
            base.LoadContent();
        }
    }
}
